#include <iostream>

using namespace std;
typedef long long LL;
#define endl '\n'
const int N = 1e5 + 10;
const LL MOD = 998244353;
LL p[N], q[N];
int n;

LL qpow(LL a, LL b)
{
    LL ret = 1;
    while(b)
    {
        if(b & 1) ret = ret * a % MOD;
        b >>= 1;
        a = a * a % MOD;
    }
    return ret;
}

void solve() 
{
    cin >> n;
    for(int i = 0; i < n; i++) cin >> p[i];
    for(int i = 0; i < n; i++) cin >> q[i];
    int maxp = p[0], maxq = q[0];
    int pos_p = 0, pos_q = 0;
    for(int i = 0; i < n; i++)
    {
        if(p[i] > maxp)
        {
            maxp = p[i];
            pos_p = i;
        }
        if(q[i] > maxq)
        {
            maxq = q[i];
            pos_q = i;
        }
        int other1 = q[i - pos_p];
        int other2 = p[i - pos_q];
        if(maxp == maxq)
        {
            if(other1 > other2) cout << ((qpow(2, maxp) + qpow(2, other1))) % MOD << " ";
            else cout << ((qpow(2, maxq) + qpow(2, other2))) % MOD << " ";
        }
        else 
        {
            if(maxp > maxq) cout << (qpow(2, maxp) + qpow(2, other1)) % MOD << " ";
            else cout << (qpow(2, maxq) + qpow(2, other2)) % MOD << " ";
        }
    }
    cout << endl;
}

int main()
{
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int T;
	cin >> T;
	while(T--)
	{
        solve();
	}
	return 0;
}